using QFramework.Framework.ResKit;
using UnityEditor;
using UnityEngine;

namespace QFramework.Example.Util._11.LoadAbAssetExample
{
    public class LoadAbAssetExample : MonoBehaviour
    {
        private ResLoader _resLoader = new();

        private void Start()
        {
            var squareTexture = _resLoader.LoadSync<Texture2D>("square", "Square");
            Debug.Log(squareTexture.name);

            // _resLoader.LoadAsync<GameObject>("gameobject", "GameObject",
            //     gameObjPrefab => { Instantiate(gameObjPrefab); });
        }

        private void OnDestroy()
        {
            _resLoader.ReleaseAll();
            _resLoader = null;
        }

#if UNITY_EDITOR
        [MenuItem("QFramework/Example/Util/11.LoadAbAssetExample", false, 11)]
        private static void MenuClicked()
        {
            EditorApplication.isPlaying = true;

            new GameObject("LoadAbAssetExample").AddComponent<LoadAbAssetExample>();
        }
#endif
    }
}